package com.vancouver.knows.business.tracker;

import java.util.HashMap;
import java.util.List;

import com.pangu.bean.PageableResult;
import com.pangu.task.IResultReceiver;
import com.pangu.task.OperateResult;
import com.pangu.task.mark.ATaskMark;
import com.vancouver.knows.business.BusinessModule;
import com.vancouver.knows.business.bean.SearchResultInfo;
import com.vancouver.knows.business.cache.SearchResultCache;
import com.vancouver.knows.business.service.impl.SearchTotalInfoHandle;
import com.vancouver.knows.business.task.mark.SearchResultTaskMark;

/**
 * 用户搜索总数列表
 * 
 * @author llf
 * 
 */
public class UserSearchTotalTracker extends ABInvokeTracker {

	public UserSearchTotalTracker(BusinessModule module, IResultReceiver resultReceiver) {
		super(module, resultReceiver);
	}

	@Override
	protected void handleTaskRefresh(ATaskMark taskMark, OperateResult result) {
		SearchResultCache searchInfoCache = module.getCacheManager().getSearchResultCache();
		searchInfoCache.deleteItemInfoIndexFromCache(taskMark);
	}

	@Override
	public String TAG() {
		return UserSearchTotalTracker.class.getSimpleName();
	}

	@SuppressWarnings("unchecked")
	@Override
	public void handleResult(OperateResult result) {
		PageableResult pageableResult = (PageableResult)result.getResultData();
		if(pageableResult == null) return;
		
		HashMap<String, Object> map = (HashMap<String, Object>) pageableResult.getContent();
		SearchResultTaskMark searchResultTaskMark = (SearchResultTaskMark) result.getTaskMark();
		searchResultTaskMark.setPageInfo(pageableResult.getPageInfo());
		List<SearchResultInfo> searchInfoList = (List<SearchResultInfo>) map.get(SearchTotalInfoHandle.SEARCH_MAP);
		module.getCacheManager().getSearchResultCache().addItemInfoToCache(searchResultTaskMark, searchInfoList);
	}
}
